Page({
  data: {
    equipmentList: [],
    loading: true,
    statusColorMap: {
      '正常': { text: '#2196F3' },
      '待维修': {text: 'rgb(218, 25, 25)' },
      '已分配': {text: '#4CAF50' },
      '报废': {text: '#F44336' }
    }
  },

  onLoad() {
    this.fetchEquipmentData();
  },

  // 获取装备数据（使用指定API）
  fetchEquipmentData() {
    this.setData({ loading: true });
    wx.request({
      url: 'http://localhost:8080/api/wechat/equipments',
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'Authorization': `Bearer ${wx.getStorageSync('token')}`
      },
      success: (res) => {
        if (res.data.code === 200 && res.data.data) {
          this.setData({ 
            equipmentList: res.data.data,
            loading: false 
          });
        console.log(res.data.data);
        } else {
          wx.showToast({ 
            title: res.data.message || '获取数据失败', 
            icon: 'none' 
          });
          this.setData({ loading: false });
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
        wx.showToast({ title: '网络错误，请稍后重试', icon: 'none' });
        this.setData({ loading: false });
      }
    });
  },

  
});